<?php

namespace App\Http\Services;

use Exception;

class AliCloudService
{
    public $secretId = '204365832';
    public $secretKey = 'jK4MpEgVe4WJk3zk7ZwFuz3IbXBr6es0';
    const appCode = 'ffd1fcc806e442d7aa5f0bb2dcbff7d4';


    //实名认证
    public function authIdcard($name = null, $idcard = null)
    {
        if (empty($name))
            throw new Exception("姓名必填", 1);

        if (empty($idcard))
            throw new Exception("身份证必填", 1);

        $host = "https://puhui.shumaidata.com";
        $path = "/id_card/check/puhui";

        $method = "GET";
        $headers = array();
        array_push($headers, "Authorization:APPCODE " . self::appCode);

        $querys = "idcard=$idcard&name=" . urlencode($name);
        $bodys = "";
        $url = $host . $path . "?" . $querys;

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        //设定返回信息中是否包含响应信息头，启用时会将头文件的信息作为数据流输出，true 表示输出信息头, false表示不输出信息头
        //如果需要将字符串转成json，请将 CURLOPT_HEADER 设置成 false
        curl_setopt($curl, CURLOPT_HEADER, false);
        if (1 == strpos("$" . $host, "https://")) {
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }

        $res = curl_exec($curl);

        curl_close($curl);

        return json_decode($res, true);
    }


}
